<template>
  <div class="page-cont">
    <van-nav-bar
      :title="question.type === 1 ? '质量详情' : '安全详情'"
      left-arrow
      @click-left="$router.go(-1)"
    />
    <div class="list">
      <div class="title">
        {{ question.issueDescription }}
      </div>
      <div class="item">
        质量源：{{ question.qualityName }}
        <span
          class="status"
          :status="question.status"
        >{{ status }}</span>
      </div>
      <div class="item">
        创建人：{{ question.username }}
      </div>
      <div class="item">
        处理人：{{ question.handleUserName }}
      </div>
      <div class="item">
        提交时间：{{ dayjs(question.createdAt).format("YYYY-MM-DD HH:mm:ss") }}
      </div>
      <div class="item">
        问题图片：
        <img
          :src="question.imageUrl"
          alt=""
        >
      </div>

      <div class="option">
        <van-button
          type="info"
          size="small"
          @click="complete"
          v-if="question.status === 0"
        >
          完成
        </van-button>
      </div>
    </div>
  </div>
</template>

<script>
import dayjs from "dayjs";
export default {
  name: "QuestionPage",
  data() {
    return {
      question: {},
      dayjs
    };
  },
  computed: {
    status() {
      return { 0: "待处理", 1: "已处理", 2: "已关闭" }[this.question.status];
    },
  },
  created() {
    this.question = JSON.parse(this.$route.query.json);
  },
  methods: {
    async complete() {
      let data = JSON.parse(JSON.stringify(this.question))
      data.status = 1
      this.$toast.loading({message: "加载中...", forbidClick: true});
      await this.api.EDIT_QUESTION(data);
      this.$toast.clear();
      this.$set(this.question, 'status', 1)
    }
  }
};
</script>

<style lang="scss" scoped>
@import "./style.scss";
.list {
  flex: 1;
  height: 0;
  overflow: hidden;
  overflow-y: auto;
  padding: 15px;
  .title {
    font-weight: 600;
    font-size: 16px;
  }
  .item {
    margin-top: 10px;
    display: flex;
    align-items: flex-start;
    font-size: 12px;
    color: #666;
    .status {
      flex: 1;
      text-align: right;
      font-size: 14px;
      &[status="0"] {
        color: #d9001b;
      }
      &[status="1"] {
        color: #f59a23;
      }
      &[status="2"] {
        color: #2467eb;
      }
    }
    img {
      width: 80px;
      height: 80px;
    }
  }
  .option {
    margin: 30px 0;
    display: flex;
    .van-button {
      flex: 1;
      margin: 10px;
    }
  }
}
</style>
